* **************************************************************************** *
*  Sierra Leone - Social Signaling and Childhood Immunization                  *
*  SICI Follow-up - Immunization behavior: Found vs Not Found         *
* **************************************************************************** *
/*
** PURPOSE:       Immunization behavior: Found vs Not Found

*/
********************************************************************************

	* Load the final data set used for analysis:
	

	use  "${Replicate_SocialSignals_dtaInter}/ListingFollowUp_analysis_attrition.dta", clear


  * ----------------------------------------------------------------------------
  * Prepare

	drop   age_pikin
	rename age_listing  age_pikin

	local VaccineVars = " bcg penta1 penta2 penta3  "

	foreach vaccine of local VaccineVars {
		drop        `vaccine'
		drop    age_`vaccine'

		rename  age_`vaccine'_listing  age_`vaccine'
		rename      `vaccine'_listing      `vaccine'
	}


	summ   age_bcg age_penta1 age_penta2 age_penta3 age_pikin

	summ   bcg penta1 penta2 penta3

	* Cleaning/filling vaccine gaps:
	replace penta2   = 1           if penta3   == 1
	replace penta1   = 1           if penta2   == 1|penta3==1
	replace bcg      = 1           if penta1   == 1|penta2==1|penta3==1

	summ   bcg penta1 penta2 penta3


  * ----------------------------------------------------------------------------


    * Code Vaccine 1 outcome
    local a = 91

    foreach var in bcg {
		replace `var' = 0          if `var'==1 & age_`var'>=`a' & age_`var'!=.
		replace `var' = 0          if `var'==. & age_pikin>=`a' & age_pikin!=.
		replace `var' = .          if age_pikin<`a'
    }


    * Code Vaccine 2 outcome
    local b = 122

    foreach var in penta1 {
		replace `var' = 0          if `var'==1 & age_`var'>=`b' & age_`var'!=.
		replace `var' = 0          if `var'==. & age_pikin>=`b' & age_pikin!=.
		replace `var' = .          if age_pikin<`b'

		replace `var' = 0          if bcg ==0 & `var'==1
    }


    * Code Vaccine 3 outcome
    local c = 152

    foreach  var in penta2 {
		replace `var' = 0          if `var'==1 & age_`var'>=`c' & age_`var'!=.
		replace `var' = 0          if `var'==. & age_pikin>=`c' & age_pikin!=.
		replace `var' = .          if age_pikin<`c'

		replace `var' = 0          if penta1 ==0 & `var'==1
    }


    * Code Vaccine 4 outcome
    * 183 days - 6 months
    local d = 183

    foreach  var in penta3 {
		replace `var' = 0          if `var'==1 & age_`var'>=`d' & age_`var'!=.
		replace `var' = 0          if `var'==. & age_pikin>=`d' & age_pikin!=.
		replace `var' = .          if age_pikin<`d'

		replace `var' = 0          if penta2 ==0 & `var'==1
    }

    summ    bcg penta1 penta2 penta3


	* Demean ANC indicator:
	tab     arm_anc, gen(anc)

	foreach var in  anc2 anc3 anc4  {
		sum    `var' if intervention_arm==1, detail
		gen    `var'_dm     = `var' - `r(mean)'
	}


	bys  found_flwup: summ bcg penta1 penta2 penta3

	summ bcg penta1 penta2 penta3



	* not eligible for BCG:
	tab      bcg, miss

	count if age_pikin < 91



	* ----------------------------------------------------------------------------
  * Check for differential Vaccination Outcomes: Found versus Not Found

	local ANC_dm  = " anc2_dm  anc3_dm anc4_dm "

	eststo clear
	
	foreach  vaccine in bcg penta1 penta2 penta3  {

		areg    `vaccine' ib0.found_flwup##ib1.intervention_arm          `ANC_dm', absorb(strata)  cluster(clinic_code)
		estadd scalar C_mean        = _b[_cons]
		estadd local Obs            = "`e(N)'"
		eststo model_`vaccine'
		
	}

	esttab  ///
	model_bcg model_penta1 model_penta2 model_penta3                        ///
	using "${Replicate_SocialSignals_OutApp}/FollowUp/Table_FollowUpMopUps_Vaccination.tex",  ///
	prehead("\begin{tabular}{l*{5}{c}} \toprule "                           ///
	"\multicolumn{1}{c}{\textbf{Dependent variable:}} & \multicolumn{1}{c}{\textbf{Vaccine 1}} & \multicolumn{1}{c}{\textbf{Vaccine 2}} & \multicolumn{1}{c}{\textbf{Vaccine 3}} & \multicolumn{1}{c}{\textbf{Vaccine 4}}  \\") ///
	scalars("C_mean        Control Group Mean"                   ///
	"Obs           Observations")                                ///
	varlabels(_cons "Control Group Mean")                                ///
	drop(_cons *_dm)  nomtitles                                          ///
	sfmt(3) b(3) se(3)  ${StarsOpt}                                      ///
	addnotes("") label se  nobaselevels noconstant noobs nolines         ///
	posthead("\midrule") postfoot("\bottomrule \end{tabular}") tex       ///
	replace

	filefilter "${Replicate_SocialSignals_OutApp}/FollowUp/Table_FollowUpMopUps_Vaccination.tex" ///
	"${Replicate_SocialSignals_OutApp}/FollowUp/Table_FollowUpMopUps_Vaccination_Found_Interviewed_NoControls.tex", from("[1em]") to(" ") replace
	erase	     "${Replicate_SocialSignals_OutApp}/FollowUp/Table_FollowUpMopUps_Vaccination.tex"



********************************************************************************
* End of the Dofile !!!
********************************************************************************
